import java.util.Vector;

class P454 {

   public static void main(String[] args) {
       try {
           int cases = Integer.parseInt(readLn());

       readLn();
       for (int k = 0; k < cases; k++) {
           process();
           if (k + 1 != cases) System.out.println();
       }
       } catch (Exception e) {
           while (true) {

           }
       }
   }

   private static void process() {
       Vector phrases = new Vector();
       String line = readLn();
       while (line != null && !line.trim().equals("")) {
           if (!phrases.contains(line)) {
               phrases.addElement(line);
           }
           line = readLn();
       }
       int length = phrases.size();
       sort(phrases);
       Vector answer = new Vector();
       for (int k = 0; k < length; k++) {
           for (int j = k + 1; j < length; j++) {
               String phrase1 = (String) phrases.elementAt(k);
               String phrase2 = (String) phrases.elementAt(j);
               if (isAnagram(phrase1, phrase2)) {
                   String answerUnit = phrase1 + " = " + phrase2;
//                    if (!answer.contains(answerUnit)) {
                       answer.addElement(answerUnit);
//                    }
               }
           }
       }
//        sort(answer);
       for (int k = 0; k < answer.size(); k++) {
           System.out.println(answer.elementAt(k));
       }
       
   }

   private static boolean isAnagram(String phrase1, String phrase2) {
       return isAnagramSimple(phrase1, phrase2);
   }

   private static boolean isAnagramSimple(String x1, String x2) {
       int[] xA1 = new int[256];
       int[] xA2 = new int[256];

       for (int k = 0; k < x1.length(); k++) {
           char c1 = x1.charAt(k);
           if (c1 != ' ') {
               xA1[((int) c1)]++;
           }
       }
       for (int k = 0; k < x2.length(); k++) {
           char c2 = x2.charAt(k);
           if (c2 != ' ') {
               xA2[((int) c2)]++;
           }
       }
       return analise(xA1, xA2);
   }

   private static boolean analise(int[] xa1, int[] xa2) {
       for (int k = 0; k < 256; k++) {
           if (xa1[k] != xa2[k]) {
               return false;
           }
       }
       return true;
   }

   private static void sort(Vector words) {
       quickSortWords(words, 0, words.size() - 1);
   }

   private static void quickSortWords(Vector vector, int i, int j) {
       if (i < j) {
           int q = partition(vector, i, j);
           quickSortWords(vector, i, q - 1);
           quickSortWords(vector, q + 1, j);
       }
   }

   private static int partition(Vector vector, int p, int r) {
       String x = (String) vector.elementAt(r);
       int i = p - 1;
       for (int j = p; j < r; j++) {
           if (((String) vector.elementAt(j)).compareTo(x) <= 0) {
               i = i + 1;
               swap(vector, i, j);
           }
       }
       swap(vector, i + 1, r);
       return i + 1;
   }

   private static void swap(Vector vector, int i, int r) {
       String aux = (String) vector.elementAt(i);
       vector.setElementAt(vector.elementAt(r), i);
       vector.setElementAt(aux, r);
   }

   static String readLn() {
       String newLine = System.getProperty("line.separator");
       StringBuffer buffer = new StringBuffer();
       int car = -1;
       try {
           car = System.in.read();
           while ((car > 0) && (car != newLine.charAt(0))) {
               buffer.append((char) car);
               car = System.in.read();
           }
           if (car == newLine.charAt(0))
               System.in.skip(newLine.length() - 1);
       } catch (java.io.IOException e) {
           return (null);
       }
       if ((car < 0) && (buffer.length() == 0))
           return (null);
       return (buffer.toString());
   }

}